package cn.com.tbshuda.shell.shell.client;


import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.BufferedInputStream;
import java.io.InputStream;
import java.util.Properties;
import java.util.Scanner;
import java.util.Set;
import java.util.zip.InflaterInputStream;

/**
 * @ClassName TestJavaShell
 * @Description TODO
 * @Autor yanni
 * @Date 2020/3/30 16:53
 * @Version 1.0
 **/
public class TestJavaShell {
    /**
     * shell脚本所在服务器配置
     */
    //public static int SHELL_EXIT_OK = 0;
    public static Log log = LogFactory.getLog(TestJavaShell.class);
    public static String connIp = "47.93.248.77";
    public static String connUser = "root";
    public static String connPwd = "Shuda1112";

    public static void main(String[] args) throws Exception {
//        Process exec = Runtime.getRuntime().exec("cmd.exe");
        boolean result = export();
    }

    public static boolean export() throws Exception {
        boolean result = false;
        // 如果当前系统是window系统需要远程ssh连接系统
//        if (isWinSystem()) {
        Scanner scan = new Scanner(System.in);
        ConnectShell connectShell = new ConnectShell(connIp, connUser, connPwd, "utf-8");
        if (connectShell.login()) {
            connectShell.openSession();
            System.out.println("建立连接");
        }
        while(scan.hasNext()){
            String url = scan.next() ;
            result = connectShell.excuteShellCommand(url);
        }
        connectShell.close();

//        }
        return result;
    }

    /**
     * 当前操作系统类型
     *
     * @return true 为windos系统，false为linux系统
     */
    public static boolean isWinSystem() {
        // 获取当前操作系统类型
        Properties prop = System.getProperties();
        String os = prop.getProperty("os.name");
        System.out.println(os);
        if (os.startsWith("win") || os.startsWith("Win")) {
            return true;
        } else {
            return false;
        }
    }
}
